<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
const obj = {
    name: "jrd",
    sayName: function(a, b) {
        console.log(this.name, a, b);
    }
}
const obj2 = {
    name: "hhh",
}
// 修改this的思路与apply完全一样，即通过this获取函数体，然后挂载到context上之后通过context[xxx]()的形式执行
// 区别就在于修改一下传参即可
Function.prototype.myCall = function(context, ...arr) {
    const fun = this;
    const tempProp = Symbol();
    context[tempProp] = fun;
    const result = context[tempProp](...arr);
    delete context[tempProp];
    return result;
}
obj.sayName.myCall(obj2, 1, 2, 3);
</script>
</body>
</html>